home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / dc15 / list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  2.4 KB  |  121 lines

  1. /*************************************
  2.    List 関連の処理をするmodule
  3. **************************************/
  4. #include<string.h>
  5. #include<direct.h>
  6. #include<dos.h>
  7. #include<direct.h>
  8. #include<stdlib.h>
  9. #include<stddef.h>
  10. #include<stdio.h>
  11. #include"list.h"
  12. #include"chain.h"
  13.  
  14. #define    TRUE    (-1)
  15. #define FALSE    0
  16.  
  17. extern    LIST    head;
  18.  
  19. /*******************************
  20.  File のlistを作ってその数を返す
  21.  *******************************/
  22. int MakeList(PARA inf)
  23. {
  24.     unsigned int dmy=0,stat=0,count=0;
  25.     char ter[13];
  26.     struct _find_t    fb;
  27.     LIST    *prev,*t;
  28.     
  29.     head.next=NULL;
  30.     _dos_setdrive(inf.drive,&dmy);
  31.     if(inf.path[0] != '\0')
  32.         if (_chdir(inf.path)==ERR){
  33.             printf("ディレクトリの指定が違います.");
  34.             exit(1);
  35.         }
  36.     
  37.     if(inf.file[0]=='\0'){
  38.         strcpy(ter,"*.doc");
  39.     }else{
  40.         strcpy(ter,inf.file);
  41.     }
  42.     
  43.     prev=&head;
  44.     stat = _dos_findfirst(ter,ALL_ATTRIBUTE,&fb);
  45.     while(stat==0){
  46.         count++;
  47.         t=(LIST *)malloc(sizeof(LIST));
  48.         if(t==NULL){
  49.             printf("Memory allocation error. \n");
  50.             exit(1);
  51.         }
  52.         prev->next=t;
  53.         t->next=NULL;        /* 次の構造体へのポインター         */
  54.         t->bf=NULL;         /* 文字列格納領域                     */
  55.         t->size=fb.size;     /* LFも含んだファイル全体の大きさ     */
  56.         t->wr_time=fb.wr_time;
  57.         t->wr_date=fb.wr_date;
  58.         t->line=0;        /* 行数カウンター */
  59.         t->flag=FALSE;
  60.         strcpy(t->file,fb.name);
  61.         prev=t;
  62.         stat=_dos_findnext(&fb);
  63.     }
  64.     return(count);
  65. }
  66.  
  67. /*********************************************
  68. purpose:
  69.   ファイルサイズの合計がsizeに近くなるように
  70.   flagをたてる。
  71. return:
  72.   フラグを立てたファイル数
  73.   
  74.  n --> 目次のファイル数 
  75. **********************************************/
  76. int SetFlag(int size)
  77. {
  78.     int sum=HEADERSIZE,count=0;
  79.     LIST    *p;
  80.     
  81.     
  82.     for(p=head.next,count=0;p!=NULL;p=p->next){
  83.         if ((sum + (p->size) + HEADERSIZE+80+INDEXLINE*80) < size ){
  84.             p -> flag = TRUE;
  85.             sum=sum+p->size+HEADERSIZE+INDEXLINE*80+80;
  86.             count++;
  87.         }
  88.     }
  89.     return(count);
  90. }
  91.  
  92. /***************************************
  93. purpose:
  94.     既に連結が終わったファイルをリスト
  95.     から削除する関数
  96. return:
  97.     削除したファイル数
  98. ****************************************/
  99. int ClearFlag(void)
  100. {
  101.     LIST *p,*prev,*del;
  102.     int count=0;
  103.     
  104.     p=head.next;
  105.     prev=&head;
  106.     while(p!=NULL){
  107.         if( p->flag == TRUE){
  108.             prev->next=p->next;
  109.             del=p;
  110.             p=prev->next;
  111.             count++;
  112.             if(del->bf!=NULL)free(del->bf);
  113.             if(del!=NULL)free(del);
  114.         }else{
  115.             prev=prev->next;
  116.             p=p->next;
  117.         }
  118.     }
  119.     return(count);
  120. }
  121.